Repository navigation
fix(sandbox): point the default image at the packaged Dockerfile - #1059
Open
morinokami wants to merge 3 commits into
Open
morinokami wants to merge 3 commits into
morinokami wants to merge 3 commits into
Conversation
Since 1.10.0, an app that imports `void/sandbox` and sets no
`sandbox.image` gets a default image that does not exist,
`node_modules/void/dist/sandbox.Dockerfile`. The package ships the file
at its root. `vp build` records the missing path, and `vp dev` stops
before it serves anything:
Error: ENOENT: no such file or directory, open
'<app>/node_modules/void/dist/sandbox.Dockerfile'
`void deploy --platform cloudflare` fails at `docker build` and says
"Sandbox image preparation failed. Start Docker and retry the
deployment." while Docker is running. 1.9.1 works. Deploys to a managed
platform are not affected: they never build the Dockerfile.
`getDefaultSandboxImage()` finds the file relative to the `void/sandbox`
entry, as `../../sandbox.Dockerfile`. 38db82c (voidzero-dev#841) moved that entry
from `dist/runtime/sandbox.mjs` to `dist/runtime/sandbox/index.mjs`, so
the same relative URL now ends in `dist/`.
## Fix
Name the Dockerfile in the package's private `imports`, as
`#self/sandbox.Dockerfile`, and resolve it from there. The path no longer
depends on where a built module sits in `dist/`, and the packed checks
already verify that every `imports` target is in the tarball.
The file stays at the package root, so a config that works around the
bug with `sandbox.image: './node_modules/void/sandbox.Dockerfile'` keeps
working.
## Tests
The default-image test checked only the file name. It now reads the
resolved path and compares it with the packaged Dockerfile. The
kitchen-sink build test checks that the Dockerfile recorded in
`dist/ssr/wrangler.json` exists. Both fail without the fix.
## Verification
- By hand, with the packed build installed in a new starter and Docker
running: `vp build` records `node_modules/void/sandbox.Dockerfile`,
`vp dev` builds the image, and the "Run a command" route of the
Sandboxes guide answers `{"exitCode":0,"stdout":"v26.12.1\n"}`.
`void deploy --platform cloudflare`, against a local stand-in for the
Cloudflare API, builds the image and goes on to the Worker upload. The
same steps on the published 1.13.1 fail as described above.
- `node .github/scripts/packed-consumer.mjs` passes for npm and pnpm,
and with `VOID_PACKED_SUITE=full`. A pnpm install resolves the default
image to an existing file too.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`void deploy --platform cloudflare` answered every failed `docker build`
of a Sandbox image with "Sandbox image preparation failed. Start Docker
and retry the deployment.". That was also the answer while Docker was
running and the build itself failed, for example on a missing Dockerfile
or a failing step. When the Docker CLI could not be started at all, the
deploy printed the raw spawn error instead (`spawn docker ENOENT`).
## Fix
After a failed build, ask the daemon with `docker info`. When it
answers, name the failure: `docker build`'s exit code and the Dockerfile,
with a pointer to Docker's output above. Keep the "Start Docker" advice
for the cases it fits: the daemon does not answer, or the CLI cannot be
started. A build that succeeds runs no extra command.
## Tests
`container-image.test.ts` runs `buildContainerImage()` with a stand-in
Docker CLI: a build that succeeds, a build that fails while the daemon
answers, a daemon that does not answer, and a CLI that cannot be
started.
## Verification
- `vpr test:all` passes on this branch: 267/267 tasks, 19,660 tests pass,
35 skipped.
- By hand, `void deploy --platform cloudflare` against a local stand-in
for the Cloudflare API, with Docker running and a Dockerfile whose
`RUN` step fails:
Sandbox image preparation failed: `docker build` exited with code 1
for <app>/Dockerfile.broken. See the Docker output above.
With `DOCKER_HOST` set to a socket that does not exist, and with a
Docker CLI that cannot be started, it prints the "Start Docker"
message.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The previous commit reports a failed `docker build` of a Sandbox image
as a build failure while Docker is running. `void deploy --platform
cloudflare` still said "Sandbox image preparation failed. Start Docker
and retry the deployment." in two cases that starting Docker does not
fix: the Docker CLI could not be started, for example because Docker is
not installed, and a signal stopped the build.
The check of the daemon also had no time limit. After a failed build
the deploy runs `docker info` to tell a failed build from a daemon that
is not running. A daemon that accepts the connection and never answers
kept the deploy waiting, without a report of the failed build.
## Fix
- When the CLI cannot be started, name the cause: "the Docker CLI could
not be started (spawn docker ENOENT). Check that Docker is installed
and retry the deployment."
- When a signal stopped the build, name the signal and do not ask the
daemon: "`docker build` was stopped by SIGTERM for <Dockerfile>."
- Give `docker info` 5 seconds. When it does not finish in time, or
cannot run, report the build failure: Docker has printed the cause
above. "Start Docker" stays for the daemon that is known not to
answer, when `docker info` exits with a non-zero code.
At the deadline the deploy kills only the CLI process. `docker info`
starts the CLI plugins just to read their metadata, before it asks the
daemon, so it has no child process while it waits. Checked with Docker
29.8.2 against a socket that accepts connections and never answers.
## Tests
`container-image.test.ts` adds a `docker info` that hangs, with the
deadline reached through fake timers, and a build that a signal stops.
The case of a CLI that cannot be started expects the new message.
## Verification
- `vpr test:all` passes on this branch: 267/267 tasks, 19,662 tests
pass, 35 skipped.
- By hand, `buildContainerImage()` with the real Docker CLI (29.8.2).
With Docker running and no Dockerfile:
Sandbox image preparation failed: `docker build` exited with code 1
for <dir>/Dockerfile. See the Docker output above.
With a failed build and `docker info` sent to a socket that never
answers, the same report comes after 5 seconds, and no Docker process
is left. With a CLI path that does not exist:
Sandbox image preparation failed: the Docker CLI could not be
started (spawn <path> ENOENT). Check that Docker is installed and
retry the deployment.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Sandboxes guide starts with a route that runs a command, and says that importing from
void/sandboxenables the required resources:An app with this route and no
sandbox.imagegets a default image that does not exist:vp buildnode_modules/void/dist/sandbox.Dockerfile, which does not existnode_modules/void/sandbox.Dockerfile, the file the package shipsvp devENOENT: no such file or directory, open '<app>/node_modules/void/dist/sandbox.Dockerfile'{"exitCode":0,"stdout":"v26.12.1\n"}void deploy --platform cloudflaredocker buildcannot read the Dockerfile, and the deploy says "Sandbox image preparation failed. Start Docker and retry the deployment." while Docker is runningmainhas the same code as 1.13.1 here. A deploy to a Void platform takes a different path: its manifest carriessandbox.platformImage, not the Dockerfile.getDefaultSandboxImage()finds the file relative to thevoid/sandboxentry, as../../sandbox.Dockerfile. 38db82c (#841), first released in 1.10.0, moved that entry fromdist/runtime/sandbox.mjstodist/runtime/sandbox/index.mjs, so the same relative URL now ends indist/. The default-image test checked only the file name.The deploy's message hid the cause. Every failed
docker buildof a Sandbox image got the "Start Docker" advice, also while Docker was running:docker buildmaindocker buildexited with code 1 for <Dockerfile>. See the Docker output above."docker buildwas stopped by SIGTERM for <Dockerfile>."spawn docker ENOENTFix
package.jsonnames the Dockerfile in the package's privateimports, as#self/sandbox.Dockerfile, andgetDefaultSandboxImage()resolves it from there. The path no longer depends on where a built module sits indist/, and the packed checks already verify that everyimportstarget is in the tarball. The file stays at the package root, so its path in an installed package does not change.docker info. "Start Docker" stays for a daemon that does not answer, whendocker infoexits with a non-zero code. A build that succeeds runs no extra command.docker infogets 5 seconds, so a daemon that accepts the connection and never answers cannot keep back the report. When the check does not finish in time, or cannot run, the deploy reports the build failure, whose cause Docker has printed above.docker infostarts the CLI plugins just to read their metadata, before it asks the daemon, so it has no child process while it waits.Tests
packages/void/test/unit/config.test.ts: the default-image case reads the resolved path and compares it with the packaged Dockerfile. Withmain'ssandbox/config.tsit fails withENOENTforpackages/void/dist/sandbox.Dockerfile.packages/void/test/integration/kitchen-sink-build.test.ts: the playground sets nosandbox.image, and the build case checks that the Dockerfile recorded indist/ssr/wrangler.jsonexists. Withmain'ssandbox/config.tsit fails.packages/void/test/unit/container-image.test.ts(new, 6 cases):buildContainerImage()with a stand-in Docker CLI.dispose()removes the local tag.docker infothat hangs, with the deadline reached through fake timers.5 of the 6
container-imagecases fail withmain'scontainer-image.ts; the first one checks whatmainalready does. The file is skipped on Windows, which does not launch the stand-in script by path.Verification
vpr test:all: builds the packages and playgrounds, runsvp checkandcheck:types, and runs the platform, unit and integration groups; 269/269 tasks pass.node .github/scripts/packed-consumer.mjspasses for npm and pnpm. Thevoidtarball containssandbox.Dockerfile.void init, Vite+) with the route above, nosandboxkey invoid.config.ts, and Docker 29.8.2 running:vp buildandvp devas in the 1.13.1 column.vp buildandvp devas in the "This PR" column. In the pnpm install, the recorded path is undernode_modules/.pnpm/and exists.buildContainerImage(), which the deploy runs for each recorded Dockerfile, with the real Docker CLI (29.8.2):main's version, with a Dockerfile that does not exist: the "Start Docker" message, whiledocker infoanswers.void-sandbox-build:<uuid>forlinux/amd64, anddispose()removes the tag.DOCKER_HOSTset to a socket that does not exist: the "Start Docker" message.docker infosent to a socket that accepts connections and never answers: the "exited with code 1" message after 5 seconds, and no Docker process is left.docker info(29.8.2) against that socket: it runs each plugin's metadata command when it starts, has no child process while it waits, and leaves none when the CLI is killed.void deploy --platform cloudflarefrom start to end, a deploy to a Void platform,VOID_PACKED_SUITE=full, a build that a signal stops outside the unit test, and Windows.🤖 Generated with Claude Code